package com.barbarossa.activity;

import com.actionbarsherlock.app.SherlockActivity;
import com.androidquery.AQuery;
import com.barbarossa.activity.R;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class OpenLinkActivity extends SherlockActivity implements OnClickListener {
//	String urls[] = {
//	"/sdcard/download/avs/NCG-006.torrent", 
//	"magnet:?xt=urn:btih:033e62154400d19c54d63110d866b9b704a1952e&tr.0=http://tracker.openbittorrent.com/announce&tr.1=udp://tracker.openbittorrent.com:80/announce&tr.2=http://tracker.thepiratebay.org/announce&tr.3=http://tracker.publicbt.com/announce&tr.4=http://tracker.prq.to/announce&tr.5=http://torrent-download.to:5869/announce&tr.6=udp://fr33domtracker.h33t.com:3310/announce", 
//	"magnet:?xt=urn:btih:2dcd726375c4ecb6063d1418e6ba383b2d5848f1&tr.0=http://tracker.openbittorrent.com/announce&tr.1=udp://tracker.openbittorrent.com:80/announce&tr.2=http://tracker.thepiratebay.org/announce&tr.3=http://tracker.publicbt.com/announce&tr.4=http://tracker.prq.to/announce&tr.5=http://torrent-download.to:5869/announce"
//	}; 
	protected AQuery aq = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
        setContentView(R.layout.openlink);
        aq = new AQuery(this);
        aq.id(R.id.buttonOK).clicked(this);
        aq.id(R.id.buttonCancel).clicked(this);
        
        Uri uri = getIntent().getData();
        if (null != uri) {
			Intent intent = new Intent(this, VodassistActivity.class);
			intent.setData(getIntent().getData());
			intent.setAction(VodassistActivity.ACTION_OPENLINK);
			startActivity(intent);
			finish();
        }
        
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		String url = null;
		switch (v.getId()) {
		case R.id.buttonCancel:
			setResult(RESULT_CANCELED);
			finish();
			break;
		case R.id.buttonOK:
			url = aq.id(R.id.editTextLink).getText().toString();
			if ((null == url)||("".equals(url.trim()))){
				Toast.makeText(this, R.string.prompt_input_empty, Toast.LENGTH_SHORT).show();
				return;
			}
			Intent data = new Intent();
			data.setData(Uri.parse(url));
			setResult(RESULT_OK, data);
			finish();
			break;
		}
	}
}
